﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web;
using System.Web.UI.HtmlControls;

namespace TA.Web.Utils
{
	public static class _ClientScriptManagerExtensions
	{
		public static void RegisterStyleResource(this ClientScriptManager csm, Type type, string resource)
		{
			string key = type.FullName + resource;
			if (!HttpContext.Current.Items.Contains(key))
			{
				Page p = HttpContext.Current.Handler as Page;
				if (p != null)
				{
					HtmlLink link = new HtmlLink();
					link.Href = csm.GetWebResourceUrl(type, resource);
					link.Attributes["res"] = "Stylesheet";
					link.Attributes["type"] = "text/css";
					p.Header.Controls.AddAt(0, link);
				}

				HttpContext.Current.Items[key] = true;
			}
		}
		public static void RegisterStyleBlock(this ClientScriptManager This, string name, string styleText)
		{
			string key = "StyleBlock" + name;
			if (!HttpContext.Current.Items.Contains(key))
			{
				Page p = HttpContext.Current.Handler as Page;
				if (p != null)
				{
					HtmlGenericControl style = new HtmlGenericControl("style");
					style.Attributes["type"] = "text/css";
					style.InnerHtml = styleText;
					p.Header.Controls.AddAt(0, style);
				}

				HttpContext.Current.Items[key] = true;
			}
			
		}
	}
}
